﻿using MySql.Data.MySqlClient;
using Npgsql;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace EPE.DBUtility
{
    public static class DataBaseConnect
    {
        public static string DataBaseType;
        public static string ConnectionString;
        private static IDbConnection DataConnection;
        private static IDbDataAdapter DataAdapter;

        public static IDbConnection DataBaseConnection()
        {
            switch (DataBaseType)
            {
                case "SQLSERVER":
                    DataConnection = new System.Data.SqlClient.SqlConnection(ConnectionString);
                    break;
                case "OLEDB":
                    DataConnection = new System.Data.OleDb.OleDbConnection(ConnectionString);
                    break;
                case "ORACLE":
                    DataConnection = new System.Data.OracleClient.OracleConnection(ConnectionString);
                    break;
                case "POSTGRE":
                    DataConnection = new NpgsqlConnection(ConnectionString);
                    break;
                case "MYSQL":
                    DataConnection = new MySqlConnection(ConnectionString);
                    break;
                default:
                    DataConnection = new System.Data.SqlClient.SqlConnection(ConnectionString);
                    break;
            }

            return DataConnection;
        }

        public static IDbDataAdapter DataAdapterType()
        {
            switch (DataBaseType)
            {
                case "SQLSERVER":
                    DataAdapter = new System.Data.SqlClient.SqlDataAdapter();
                    break;
                case "OLEDB":
                    DataAdapter = new System.Data.OleDb.OleDbDataAdapter();
                    break;
                case "ORACLE":
                    DataAdapter = new System.Data.OracleClient.OracleDataAdapter();
                    break;
                case "POSTGRE":
                    DataAdapter = new NpgsqlDataAdapter();
                    break;
                case "MYSQL":
                    DataAdapter = new MySqlDataAdapter();
                    break;
                default:
                    DataAdapter = new System.Data.SqlClient.SqlDataAdapter();
                    break;
            }
            return DataAdapter;
        }

    }
}
